<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>Gentelella Alela! | </title>

    <!-- Bootstrap -->
    <link href="/resources/gentelella/vendors/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="/resources/gentelella/vendors/font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <!-- NProgress -->
    <link href="/resources/gentelella/vendors/nprogress/nprogress.css" rel="stylesheet">
    <!-- iCheck -->
    <link href="/resources/gentelella/vendors/iCheck/skins/flat/green.css" rel="stylesheet">

    <!-- bootstrap-progressbar -->
    <link href="/resources/gentelella/vendors/bootstrap-progressbar/css/bootstrap-progressbar-3.3.4.min.css" rel="stylesheet">
    <!-- JQVMap -->
    <link href="/resources/gentelella/vendors/jqvmap/dist/jqvmap.min.css" rel="stylesheet"/>
    <!-- bootstrap-daterangepicker -->
    <link href="/resources/gentelella/vendors/bootstrap-daterangepicker/daterangepicker.css" rel="stylesheet">

    <!-- Custom Theme Style -->
    <link href="/resources/gentelella/css/custom.min.css" rel="stylesheet">
    <link rel="stylesheet" href="/resources/datatables/dataTables.bootstrap.css?v=2">
    <link href="/resources/gentelella/vendors/datatables.net-bs/css/dataTables.bootstrap.min.css" rel="stylesheet">
    <link href="/resources/paginator/css/bootstrap-combined.min.css" rel="stylesheet">
    <link href="/resources/css/self.css" rel="stylesheet">
    <!-- table -->
    <script src="/resources/js/jquery-1.11.1.min.js"></script>
    <script src="/resources/datatables/jquery.dataTables.min.js"></script>
    <script src="/resources/datatables/dataTables.bootstrap.min.js"></script>
    <script src="/resources/paginator/js/bootstrap-paginator.js"></script>
    <script src="/resources/js/self.js"></script>
    <script src="/resources/gentelella/vendors/bootstrap/js/modal.js"></script>
    <script src="/resources/js/fk.js"></script>
    <script src="/resources/gentelella/vendors/bootstrap/js/modal.js"></script>
    <script type="text/javascript" src="/resources/js/md5.js"></script>
    <style type="text/css">
        .form-data{
            width: 150px !important;
        }


    </style>
</head>

<body >
<div class="col-md-12">
    <div class="box-body" style="padding-bottom:10px;">
        <div class="row form-inline" style="margin-left: 20px;">

            <div class="form-group">
                <label>公司名称:</label>
                <input type="text" class="form-control form-data" name="name"/>
                <input type="hidden" class="form-control form-data" name="type" value="staff"/>
            </div>


            <div class="form-group">
                <label>法人:</label>
                <input type="text" class="form-control form-data" name="personInCharge"/>
            </div>
            <div class="form-group">
                <label>经营行业:</label>
                <input type="text" class="form-control form-data" name="business"/>
            </div>
            <button type="button"  onclick="searchData()" class="btn btn-primary">查询</button>


        </div>

        <div class="row form-inline" style="margin-left: 20px;margin-top: 10px;">

            <button type="button" onclick="showRegister()" class="btn btn-success">企业备案</button>
            <button type="button" onclick="opneAuditDailog()" class="btn btn-success"
                   >审批</button>
            <button type="button" onclick="openPasswordDialog()" class="btn btn-success">修改密码</button>

        </div>
    </div>
    <div class="x_panel">

        <table id="example" class="table table-bordered table-striped dataTable" cellspacing="0" width="100%">
            <thead>
            <tr>
                <th>选择</th>
                <th>序号</th>
                <th>名称</th>
                <th>经营行业</th>
                <th>创建时间</th>
                <th>状态</th>
                <th>法人</th>
                <th>联系电话</th>
                <th>操作</th>
            </tr>
            </thead>
        </table>
        <div id="example_page">
        </div>
    </div>

</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                   审核
                </h4>
            </div>
            <div class="modal-body">
                <div>
                    同意:<input type="radio" name="auditStatus" value="auditSuccess">
                    拒绝:<input type="radio" name="auditStatus" value="auditFail">
                </div>
                <div>
                    <textarea  rows="5" style="width:100%;" id="auditResult"></textarea>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" onclick="auditCompany()">
                    确定
                </button>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                </button>

            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<div class="modal fade" id="password" tabindex="-1" role="dialog" aria-labelledby="passwordLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="passwordLabel">
                    修改密码
                </h4>
            </div>
            <div class="modal-body">
                <div>
                    最新密码
                    <input id="newPassword" type="password" style="width:50%;" />

                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" onclick="updatePassword()">
                    确定
                </button>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                </button>

            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

</body>
<script type="text/javascript">
    //列名称
    var columns = ["id","id","id","business","startTime","status","personInCharge","telephone","id"];
    function getStatusName(status) {
        var statusName = "";
        if(status ==='inProduction'){
            statusName ='正常';
        }else if(status ==='discontinued'){
            statusName ='锁定';
        }else if(status ==='suspend'){
            statusName ='锁定';
        }else if(status ==='closed'){
            statusName ='注销';
        }
        return statusName;
    }
    var createdCellFun = function (td, cellData, rowData, row, col) {
        /* $(td).css('color', 'red');*/

        switch (col){
            case 0:
                 var html = "";
                html += "<input type='checkbox' value='"+cellData+"' name='select'/>";
                $(td).html(html);
                break;
            case 1:

                $(td).html( (row+1));
                break;
            case 2:
                var html = "";
                html += "<a href='javascript:void(0);' onclick='showInfo(\""+cellData+"\")' >"+rowData.name+"</a>";

                $(td).html(html);
                break;
            case 4:
                $(td).html(new Date(cellData).format("yyyy-MM-dd"));
                break;
            case 5:
                $(td).html(getStatusName(cellData));
                break;
            case 8:
                var html = "";
                /*html += "<a href='javascript:void(0);' onclick='edit(\""+cellData+"\")' >修改</a><br>";
                html += "<a href='javascript:void(0);' onclick='modifyCUser(\""+cellData+"\")' >维护账号</a><br>";
                html += "<a href='javascript:void(0);' onclick='showPractitioner(\""+cellData+"\")' >从业人员</a><br>";
                html += "<a href='javascript:void(0);' onclick='modifyCDevice(\""+cellData+"\")' >维护设备</a><br>";
                html += "<a href='javascript:void(0);' onclick='showRegister(\""+cellData+"\")' >企业备案</a><br>"; */
                if(!isNullOrUndefined(rowData.fileInfoList)&&!isNullOrUndefined(rowData.fileInfoList[0])){
                    html += "<a href='javascript:void(0);' onclick='downLoadFileId(\""+rowData.fileInfoList[0].path+"\",\""+rowData.fileInfoList[0].name+"\")' >汇编文件</a>";
                }
                $(td).html(html);
        }
    }
    $(function () {
        setTitle("基本信息>企业信息");
        buildPage("#example");
        var param = getParam();
        initDataTable("#example", "/admin/buyCompany/list.do",param,columns,createdCellFun);
    });
    function getParam(){
        var param = getPageDataByClass("form-data");
        param['page']= 1;
        param['size']= 10;
        param['auditStatus'] = 'auditSuccess';
        return param;
    }
    function buildPage(element) {
        var param = getParam();
        //点击分页页面按钮
        var clickFun = function (e, originalEvent, type, page) {
            //构建查询参数
            param = getParam();
            param['size'] = 10;
            _page = page;
            param['page'] = page;
            initDataTable("#example", "/admin/buyCompany/list.do", param, columns, createdCellFun);
        }
        $.ajax({
            url:"/admin/buyCompany/count.do?_t=" + new Date().getTime(),
            data: param ,
            type:'post',
            dataType:"json",  //xml  html   script  jsonp
            success:function(result){
                initPage($("#example_page"),1,result.data,clickFun);
            }
        });
    }
    function searchData() {
        var param = getParam();
        initDataTable("#example", "/admin/buyCompany/list.do", param, columns, createdCellFun);
        buildPage("#example");
    }

    /*function edit(id) {
        goto("company_edit.html",{"id":id});
    }*/


    function downLoadFile(url) {
        window.location.href=url;
    }
    function showRegister() {
        var companyId = getOneSelectChecked();
        if(isNullOrUndefined(companyId)){
            alert("请选择要修改的数据,并且只能选择一条");
            return;
        }
        goto("companyRegister_show.html",{"companyId":companyId,"back_url":"company_r_list.html","data_type":'buy'});
    }




    function edit() {
        var id = getOneSelectChecked();
        if(isNullOrUndefined(id)){
            alert("请选择要修改的数据,并且只能选择一条");
            return;
        }
        goto("company_edit.html",{"id":id});
    }
    function showInfo(id) {
        goto("buyCompany_show.html",{"id":id,"back_url":"buy_list.html"});
    }
    //通用 获取列表中选择的数据的id
    function getSelectChecked() {
        var ids = [];
        $("input[name='select']:checked").each(function(){
            ids.push($(this).prop("value"));
        });
        return ids;
    }
    function getOneSelectChecked() {
        var ids = getSelectChecked();
        if(ids.length == 0 || ids.length > 1) {
            return null;
        }
        return ids[0];
    }
    function checkAllSelect(node) {
        if($(node).prop("checked")) {
            $("input[name='select']").each(function(){
                $(this).prop("checked", true);
            });
        } else {
            $("input[name='select']").each(function(){
                $(this).prop("checked", false);
            });
        }
    }
    function showSecurityPeople() {
        var companyId = getOneSelectChecked();
        if(isNullOrUndefined(companyId)){

            return;
        }
        goto("practitioner_list.html",{"companyId":companyId,"securityPeople":"valid"});
    }
    function showPurchasePeople() {
        var companyId = getOneSelectChecked();
        if(isNullOrUndefined(companyId)){

            return;
        }
        goto("practitioner_list.html",{"companyId":companyId,"purchasePeople":"valid"});
    }
    function showSeller() {
        var companyId = getOneSelectChecked();
        if(isNullOrUndefined(companyId)){

            return;
        }
        goto("practitioner_list.html",{"companyId":companyId,"seller":"valid"});
    }
    function modifyMV() {
        var companyId = getOneSelectChecked();
        if(isNullOrUndefined(companyId)){

            return;
        }
        goto("monitor_video_list.html",{"companyId":companyId,"seller":"valid"});
    }
    function opneAuditDailog() {
        var companyId = getOneSelectChecked();
        if(isNullOrUndefined(companyId)){
            alert("请选择要修改的数据,并且只能选择一条");
            return;
        }
        $('input[type=radio][name="auditStatus"]:checked').prop("checked", false);
        $("#auditResult").html("");
        $('#myModal').modal('show');
    }
    function auditCompany() {
        var companyId = getOneSelectChecked();
        var auditStatus = $("input[name='auditStatus']").val();
        if(isNullOrUndefined(auditStatus)){
            alert("请选择是否审批通过！");
            return;
        }
        var auditResult = $("#auditResult").val();
        $.ajax({
            url:"/admin/buyCompany/audit.do?_t=" + new Date().getTime(),
            data: {"companyId":companyId,"auditStatus":auditStatus} ,
            type:'post',
            dataType:"json",  //xml  html   script  jsonp
            success:function(result){
                $('#myModal').modal('hide');
                searchData();
            }
        });
    }
    function openPasswordDialog() {
        var companyId = getOneSelectChecked();
        if(isNullOrUndefined(companyId)){
            alert("请选择要修改的数据,并且只能选择一条");
            return;
        }

        $("#newPassword").val("");
        $('#password').modal('show');
    }
    function updatePassword() {
        var password =  hex_md5($('#newPassword').val());
        var id = getOneSelectChecked();
        $.ajax({
            url: "/admin/buyCompany/updatePassword.do",
            data: {"id":id,"password":password},
            dataType: 'json',
            type: 'post',
            success: function (data) {
                console.log(data);
                if (data.success) {
                    $('#password').modal('hide');


                } else {
                    alert(data.msg);
                }
            }
        });
    }
</script>
</html>